package com.hxgz.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxgz.dao.CommonJntdrugsMapper;
import com.hxgz.pojo.CommonJntdrugs;
import com.hxgz.service.ICommonJntdrugsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 平台药品配码 服务实现类
 * </p>
 *
 * @author wuke
 * @since 2021-04-23
 */
@Service
public class CommonJntdrugsServiceImpl extends ServiceImpl<CommonJntdrugsMapper, CommonJntdrugs> implements ICommonJntdrugsService {

    @Autowired
    CommonJntdrugsMapper commonJntdrugsMapper;


    @Override
    @Async
    public Boolean clearCom() {
        CommonJntdrugs commonJntdrugs = new CommonJntdrugs();
        List<CommonJntdrugs> commonJntdrugsList = commonJntdrugsMapper.selectList(new QueryWrapper<>(commonJntdrugs));
        for (CommonJntdrugs jntdrugs : commonJntdrugsList) {
            String packagingSpecifications = jntdrugs.getPackagingSpecifications();
            if (StringUtils.isNotEmpty(packagingSpecifications)) {
                String packageNum = packagingSpecifications.replaceAll("[^0-9]", "");
                String minUnit = StringUtils.substringAfter(packagingSpecifications, packageNum);
                jntdrugs.setMinUnit(minUnit);
                jntdrugs.setPackageNum(packageNum);
            } else {
                continue;
            }
            int i = commonJntdrugsMapper.updateById(jntdrugs);
        }
        return true;
    }
}
